package nav;

import java.util.ArrayList;
import java.util.List;

public class CoordinateCollectionImpl implements CoordinateCollection{

	List<Coordinate> coordinates = new ArrayList<Coordinate>();

	private double top = Double.MIN_VALUE;
	private double bottom = Double.MAX_VALUE;
	private double left = Double.NEGATIVE_INFINITY;
	private double right = Double.POSITIVE_INFINITY;
	
	public CoordinateCollectionImpl(){
        
    }

	@Override
	public void add(Coordinate coordinate) {
        coordinates.add(coordinate);
        if(coordinate.getLat()>top)
        	top = coordinate.getLat();
        if(coordinate.getLat()<bottom)
        	bottom = coordinate.getLat();
        if(coordinate.getLong()>left)
        	left = coordinate.getLong();
        if(coordinate.getLong()<right)
        	right = coordinate.getLong();		
	}

	@Override
	public List<Coordinate> getAll(){
		return coordinates;
	}
	
	@Override
    public Coordinate getCoordinate(int index){
    	return coordinates.get(index);
    }

	@Override
	public void removeCoordinate(Coordinate coord) {
		coordinates.remove(coord);
	}

	@Override
	public double getRangeLeft() {
		return left;
	}

	@Override
	public double getRangeRight() {
		return right;
	}

	@Override
	public double getRangeBottom() {
		return bottom;
	}

	@Override
	public double getRangeTop() {
		return top;
	}

	@Override
	public void clear() {
		coordinates.clear();
	}
}
